import { getPageList } from "@/services";
import { IPageInfo, IQueryForm, IUserInfo } from "@/utils/types";
import { makeAutoObservable, runInAction } from "mobx"

class Page{
  constructor(rootState: any) {
    this.rootState = rootState;
    makeAutoObservable(this)
  }
  page = 1;
  pageSize = 12;
  rootState = null;
  pageList: IPageInfo[] = [];
  pageLength: number = 0;

  async getPageList(query: Partial<IQueryForm>){
    let queryForm: IQueryForm = {
      ...query,
      page: this.page,
      pageSize: this.pageSize
    }
    let result = await getPageList(queryForm);
    if (result.data){
      runInAction(()=>{
        this.pageList = result.data[0];
        this.pageLength = result.data[1];
      })
    }
  }
}

export default Page;